package day04;

import java.util.ArrayList;

/**
 * @author jhj
 * @date 2022/5/12 10:05
 */
public class TestFor {
    public static void main(String[] args) {
        System.out.println("==================");
        TestFor testFor = new TestFor();
        int[] a = {1,5,4,7,9};
        int[] ints = new int[a.length];
        int j = 0;
        for (int i : a) {
            if (testFor.compareA(i)){
                continue;
            }else {
                ints[j++] = i;
            }
        }
        for (int anInt : ints) {
            if (anInt!=0)
                System.out.println(anInt);
        }
        testFor.testfor();
        testFor.testForEach();
        testFor.testforEach1();
    }
    //判断奇数
    public boolean compareA(int a){
        if (a == 1||a == 2) return true;
        for (int i = 2; i < a; i++) {
            if (a%i == 0) return false;
            else continue;
        }
        return true;
    }

    public void testForEach(){
        System.out.println("==================");
        int[] a= {1,2,4,5};
        for (int i : a) {
            System.out.println(i);
        }
    }
    public void testfor(){
        System.out.println("==================");
        int[] a= {1,2,4,5};
        int l = 0;
        for (;;){
            System.out.println(a[l]);
            if (++l == a.length-1) {
                break;
            }
        }
    }
    public void testforEach1(){
        System.out.println("==================");
        ArrayList<Integer> objects = new ArrayList<>();
        objects.add(1);
        objects.add(2);
        objects.add(3);
        objects.add(4);
        objects.forEach((o)->{
            o = o+1;
            System.out.println(o);
        });
        }
}
